<template>
  <div >
    <view>
      <swiper :images="images" />
    </view>
    <div style="width: 100%;margin: 10px auto;">
      <div class="content">
        <div class="product">
          <div class="title">{{fname}}</div>
          <div v-for="(item,key) in list" :key="key" class="item">
            <img :src="item.img" alt="" class="proimg" mode="widthFix" @click="goContent(item.id)"/>
            <div class="cont">
              <div class="name"># {{item.name}} #</div>
              <div class="more" @click="goContent(item.id)">查看详情</div>
            </div>
          </div>

        </div>
      </div>

      <div>
        <i-load-more :tip="loadingtip" :loading="loadingtrue"/>
      </div>

    </div>
  </div>
</template>

<script>
  import swiper from "@/components/swiper";
  export default {
    components: { swiper },
    name: "",
    data() {
      return {
        images: [
          {
            url:
              "https://cnsder.com/static/uploads/banner/9156acda0e0cd36a476b30e6e20a863a.jpg",
          }
        ],
        loadingtip:'',
        loadingtrue:true,
        list: [],
        page: 1,
        total_page: 0,
        id:'',
        fname:'',
        fcateid:''
      }
    },
    methods: {
      requestData() {
        const that = this;
        console.log(that)
        var api='https://cnsder.com/applist2';
        wx.request({
          url: api, //仅为示例，并非真实的接口地址
          data: {
            page: that.page,
            id:that.id
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success: function (res) {
            wx.stopPullDownRefresh()
            wx.hideNavigationBarLoading()
//            const data = res.data
            console.log(res.data.total_page)

            if (that.page > 1) {
              that.list.push(...res.data.result)
            }
            else {
              that.list = res.data.result
              console.log(that.list)
            }
            if(res.data.total_page==0)
            {
              console.log(res.data.total_page);
              that.loadingtrue=false
              that.loadingtip='暂无数据'
              console.log('数据加载完了')
            }
            if(res.data.total_page==1)
            {
              console.log(res.data.total_page);
              that.loadingtrue=false
              that.loadingtip='暂无数据'
              console.log('数据加载完了')
            }
            that.total_page = res.data.total_page
            wx.setNavigationBarTitle({title: res.data.fname})
            that.fname=res.data.fname
            that.fcateid=res.data.fcateid
          }
        })
      },
      goContent(id,fcateid) {
        // console.log(aid)
        const that = this;
        console.log(that.fcateid);
        if(that.fcateid==null)
        {
          const url = '../proscontent/main?id=' + id;
          wx.navigateTo({url});
        }
        else{
          const url = '../prolist2/main?id=' + fcateid;
          wx.navigateTo({url});
        }
      }
    },
    onLoad: function(options) {
      wx.showNavigationBarLoading()
      var id=options.id;
      var page ='';
      this.id=id;
      this.page=1;
      this.loadingtrue=true,
      this.loadingtip='正在加载'
      this.requestData(id,page);
    },
    onReachBottom() {
      if (this.page >=this.total_page) {
        this.loadingtrue=false
        this.loadingtip='暂无数据'
        console.log('数据加载完了')
      }
      else {
        this.page = this.page + 1
        this.requestData();
      }
    },
    onPullDownRefresh() {
      console.log('下拉刷新')
      this.loadingtrue=true
      this.loadingtip='正在加载'
      this.page = 1
      this.requestData()
    },
  }
</script>

<style scoped lang=scss>
  .info{
    width: 90%;
    margin:10px auto;
  }
  .content{
    width: 100%!important;
    margin-top:20px;
  }
  .loadingshow{
    display: none;
  }
  .product {
    display: -webkit-flex;
    display: flex;
    flex-wrap:wrap;
    padding:0px 0 15px;
    width:100%;
    .title{
      width: 100%;
      height: 50px;
      line-height: 50px;
      background: #fff;
      border-left: 4px solid #e2091a;
      padding-left: 15px;
      font-size: 18px;
      font-weight: bold;
    }
    .item{
      width: 100%;
      display: -webkit-flex;
      display: flex;
      flex-direction:column;
      border-bottom: 5px solid #ddd;
      background: #fff;
      img{
        width: 100%;
      }
      .cont{
        width: 90%;
        padding:20px 5%;
        .name{
          font-size: 12px;
          text-align: left;
          color: #abaaaa;
        }
        .more{
          font-size: 14px;
          color: #fff;
          background: #000;
          text-align: center;
          width: 70px;
          height: 30px;
          line-height: 30px;
          margin-top: 10px;
          border: 1px solid #000;
        }
      }

    }
  }
</style>
